package org.zju.demo;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Created by ZJDX on 2015/9/18.
 */
public class A {
    static class B extends Thread{
        AtomicBoolean atomicBoolean = new AtomicBoolean(false);
        public void terminal() {
            atomicBoolean.set(true);
        }
        public void run() {
            while(true) {
                System.out.println("B----");
                try {
                    Thread.sleep(5000);
                }catch (Exception e) {
                    e.printStackTrace();
                }
                if (atomicBoolean.get()) {
                    System.out.println("terminal");
                    break;
                }
            }
        }
    }

    public static void main(String[] args) {
        B b = new B();
        b.start();
        try{
            Thread.sleep(1000);
            System.out.println("before terminal");
            b.terminal();
            System.out.println("after terminal");
            Thread.sleep(3000);
        }catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("end");
    }
}
